-
-
Notifications
You must be signed in to change notification settings - Fork 370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Skip metric regularization if adapt window=0 #3037
base: develop
Are you sure you want to change the base?
Conversation
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
Although I largely agree with the update technically inverse metric updating is skipped for both adapt_window = 0 and adapt_window = 1. I'll change the pull name before merging. |
covar = (n / (n + 5.0)) * covar | ||
+ 1e-3 * (5.0 / (n + 5.0)) | ||
* Eigen::MatrixXd::Identity(covar.rows(), covar.cols()); | ||
if (estimator_.num_samples() > 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this behavior probably won't be obvious I think we need to wire a message to the logger. Both here and in var_adaptation
can you add a std::string& msg
argument which passes the message "Warning: inverse metric is not updated for window sizes less than 2". Then we can pass that to the logger in all of the transition
implementations.
@@ -27,3 +27,32 @@ TEST(McmcCovarAdaptation, learn_covariance) { | |||
} | |||
EXPECT_EQ(0, logger.call_count()); | |||
} | |||
|
|||
TEST(McmcCovarAdaptation, learn_covariance_one_sample) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corresponding test in var_adaptation_test.cpp?
If changes are made according to #3027 (comment) then no warning message would be needed for the base_window = 0 case, in which case messages wouldn't have to be passed, but if inverse metric updating is also disabled for base_window = 1 then I think we still need the message. |
Submission Checklist
./runTests.py src/test/unit
make cpplint
Summary
This came up in #3027 (comment)
CmdStan accepts
window=0
as a valid argument even though it means the adaptation cannot possibly estimate the inverse metric. The intended effect appears to be adapt only stepsize and leave the metric at its initial value, either the default identity or a user specified value. That works but only if you also setinit_buffer=0
. Ifinit_buffer>0
the sampler tries to update the metric anyway and messes it up.The metric update code is
stan/src/stan/mcmc/var_adaptation.hpp
Lines 24 to 28 in 35a15c8
The Welford estimator's
sample_variance()
is a no-op if there are not enough samples so that part's fine.The problem is the subsequent regularization which in case of zero samples just discards the (unchanged) metric.
The fix is to simply skip the regularization when
sample_variance()
didn't do anything.Intended Effect
Setting
window=0
always keeps the initial metric.How to Verify
Run the
examples/bernoulli
model withadapt init_buffer=10 window=0
and look for the mass matrix in output.csv.On develop it says
On this branch
Side Effects
Documentation
Copyright and Licensing
Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company): Niko Huurre
By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses: